interface DetailItem {
  title: string;
  desc: string;
  img: string;
}

export function useWeChatShare() {
  const setShareData = (detail: DetailItem) => {
    window.wx.ready(() => {
      // 设置好友分享数据
      window.wx.updateAppMessageShareData({
        title: detail.title,
        desc: detail.desc,
        link: window.location.href,
        imgUrl: detail.img,
        success: function() {
          console.log('分享给好友成功');
        },
      });

      // 设置朋友圈分享数据
      window.wx.updateTimelineShareData({
        title: detail.title,
        link: window.location.href,
        imgUrl: detail.img,
        success: function() {
          console.log('分享到朋友圈成功');
        },
      });
    });
    window.wx.error((err: any) => {
      console.error('微信SDK配置错误:', err);
    });
  };

  return { setShareData };
}
